package org.lanlab.storode.common;

/**
 * @author dove
 * @since 2020/1/9 14:32
 */
public class CommonResult<T> {
    private int code;
    private String message;
    private T data;

    protected CommonResult() {

    }

    protected CommonResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage(), data);
    }

    public static <T> CommonResult<T> success(T data, String message) {
        return new CommonResult<>(ResponseCode.SUCCESS.getCode(), message, data);
    }

    public static <T> CommonResult<T> failed(String message) {
        return new CommonResult<>(ResponseCode.FAILED.getCode(), message, null);
    }

    public static <T> CommonResult<T> failed(ResponseCode code) {
        return new CommonResult<>(code.getCode(), code.getMessage(), null);
    }

    public static <T> CommonResult<T> failed() {
        return new CommonResult<>(ResponseCode.UNKNOWN.getCode(), ResponseCode.UNKNOWN.getMessage(), null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
